#include <bits/stdc++.h>

class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        set<int> order;
        for (int i = 0; i < nums.size(); i++) {
            order.insert(nums[i]);
        }
        int maxn = 1, cnt = 1;
        auto it1 = order.begin();
        auto it2 = order.begin();
        it2++;
        if (it1 == order.end())
            return 0;
        for (; it1 != order.end() && it2 != order.end(); it1++, it2++) {
            // cout<<*it1<<' ';
            if (*it1 + 1 == *it2) {
                cnt++;
                // cout<<cnt<<endl;
                if (cnt > maxn)
                    maxn = cnt;
            } else {
                cnt = 1;
            }
        }
        return maxn;
    }
};
